package combat;

import java.awt.Point;

/**
 * ConcreteCommand subclass for fire command
 *
 */

public class ShootCommand implements AbstractCommand {

    

	@Override 
	/**
	 * Fires a bullet when the fire command is pressed
	 * Also handles how bullets react at specific starting points
	 * @param PlayerManger calling the command
	 */
	public void execute(PlayerManager pm) {
		int BulletOffset = pm.getBulletOffset();
		
		//get the location of my player
        Point loc = pm.getPlayer().getLocation();
        
        //Get the direction this player is going
        int dir = pm.getPlayer().getDirection();
        Point bulletStart = loc;
        
        switch( dir )
        {
            //start the bullet, giving it an offset enough so I'm not 
            //shooting myself
            case( 1 ):
                bulletStart = new Point( loc.x, loc.y-BulletOffset );
                break;
            case( 2 ):
                bulletStart = new Point( loc.x+BulletOffset, loc.y-BulletOffset );
                break;
            case( 3 ):
                bulletStart = new Point( loc.x+BulletOffset, loc.y );
                break;
            case( 4 ):
                bulletStart = new Point( loc.x+BulletOffset, loc.y+BulletOffset );
                break;
            case( 5 ):
                bulletStart = new Point( loc.x, loc.y+BulletOffset );
                break;
            case( 6 ):
                bulletStart = new Point( loc.x-BulletOffset, loc.y+BulletOffset );
                break;
            case( 7 ):
                bulletStart = new Point( loc.x-BulletOffset, loc.y );
                break;
            case( 8 ):
                bulletStart = new Point( loc.x-BulletOffset, loc.y-BulletOffset );
                break;
            default:
        }
        
        //place the bullet on the screen
        pm.getBullet().place( bulletStart, dir );
	}

}
